/*
 * Change Logs:
 * Date           Author       Notes
 * 2022-03-27     chenbin
 */
#include "fdown.h"
#if (FBOOT_USING_FDOWN == 1)

#define DBG_ENABLE
#define DBG_SECTION_NAME "fdown"
#define DBG_LEVEL DBG_INFO
#include <rtdbg.h>

#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH)
#include <finsh.h>

static const char *help_info[] =
{
#if (FDOWN_USING_HTTP == 1)
	"fdown http2fal <http url>  <fal part name>\n\r",
#if (FBOOT_USING_FILESYSTEM == 1)
	"fdown http2fs  <http url>  <fs path>\n\r",
#endif /* FBOOT_USING_FILESYSTEM */

#endif /* FDOWN_USING_HTTP */
		
#if (FDOWN_USING_YMODEM == 1)
	"fdown ym2fal  <device name> <fal part name>\n\r",
#if (FBOOT_USING_FILESYSTEM == 1)
	"fdown ym2fs   <device name> <fs path>\n\r",
#endif /* FBOOT_USING_FILESYSTEM */

#endif /* FDOWN_USING_YMODEM */
};

void fdown_cmd(rt_uint8_t argc, char **argv)
{
	if (argc >= 4)
	{
		const char *cmd = argv[1];
#if (FDOWN_USING_HTTP == 1)
		if (!rt_strcmp(cmd, "http2fal"))
		{
			fdown_http2fal(argv[2],argv[3]);
			return;
		}
#if (FBOOT_USING_FILESYSTEM == 1)
		if (!rt_strcmp(cmd, "http2fs"))
		{
			fdown_http2fs(argv[2],argv[3]);
			return;
		}
#endif /* FBOOT_USING_FILESYSTEM */

#endif /* FDOWN_USING_HTTP */
		
#if (FDOWN_USING_YMODEM == 1)
		if (!rt_strcmp(cmd, "ym2fal"))
		{
			fdown_ym2fal(argv[2],argv[3]);
			return;
		}
#if (FBOOT_USING_FILESYSTEM == 1)
		if (!rt_strcmp(cmd, "ym2fs"))
		{
			fdown_ym2fs(argv[2],argv[3]);
			return;
		}
#endif /* FBOOT_USING_FILESYSTEM */

#endif /* FDOWN_USING_YMODEM */
	}
	{
		rt_kprintf("usage:\n");
		for (int i = 0; i < sizeof(help_info) / sizeof(char *); i++)
		{
			rt_kputs(help_info[i]);
		}
		rt_kprintf("\n");
	}
}
MSH_CMD_EXPORT_ALIAS(fdown_cmd, fdown, fdown [fal/fs]);

#endif

#endif
